const { Int32 } = require('bson');
const mongoose = require('mongoose');
const {Schema, model} = mongoose;

const playerSchema = new Schema({
        playerId: { type: Number, unique: true },
        name: { type: String },
        height: { type: Number },
        weight: { type: Number },
        '2016teamId': { type: String },
        '2016shirtNo': { type: String },
        birthYear: { type: Number },
        '2017teamId': { type: String },
        '2017shirtNo': { type: String },
        '2018teamId': { type: String },
        '2018shirtNo': { type: String },
        '2019teamId': { type: String },
        '2019shirtNo': { type: String },
        '2020teamId': { type: String },
        '2020shirtNo': { type: String },
        playerIdNew: { type: String },
        playerValue: { type: String },
        country: { type: String },
        /**name:   { type: String },
        area:   { type: String },
        format: { type: String },
        type:   { type: String },
        category: { type: String },
        gender: { type: String },
        divisionLevel: { type: Number },*/
    },{
        toJSON: {
            transform: function(doc, ret, options) {
                delete ret._id;
                delete ret.__v;
                return ret;
            }
        }
    });

playerSchema.static('findById', function(id) { return this.findOne({playerId:id}); });
playerSchema.static('removeById', function(id) { return this.remove({id}); });
playerSchema.static('upsert', function(id, playerData) {
    return this.findOneAndUpdate({id}, playertData, { new:true, upsert: true })
});

module.exports = model('players', playerSchema);
